#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn=400;
int n, p;
ll f[maxn+1][maxn+1], g[maxn+1][maxn+1], a[maxn+1][maxn+1], b[maxn*maxn+1], fact[maxn+1], invf[maxn+1];

ll qpower(ll a, int n) {
    ll s=1;
    for (; n; n/=2) {
        if (n&1) s=s*a%p;
        a=a*a%p;
    }
    return s;
}

void initPow(int n) {
    b[0] = 1;
    for (int i=1; i<=n*n; i++) b[i] = b[i-1]*2%p;
    for (int i=0; i<=n; i++) {
        a[i][0] = 1;
        a[i][1] = b[i]-1;
        for (int j=2; j<=n; j++) a[i][j] = a[i][j-1]*a[i][1]%p;
    }
}

void initFact(int n) {
    fact[0] = 1;
    for (int i=1; i<=n; i++) fact[i] = fact[i-1]*i%p;
    invf[n] = qpower(fact[n], p-2);
    for (int i=n; i; i--) invf[i-1] = invf[i]*i%p;
}

ll c(int n, int m) { return fact[n]*invf[m]%p*invf[n-m]%p; }

int main() {
    freopen("far.in", "r", stdin);
    freopen("far.out", "w", stdout);

    scanf("%d %d", &n, &p);
    initPow(n);
    initFact(n);

    f[1][1] = 1;
    g[1][1] = 0;
    for (int i=1; i<n; i++) {
        for (int j=1; i+j<=n; j++) {
            for (int k=1; k<=i; k++) {
                f[i+j][j] = (f[i+j][j]+f[i][k]*b[j*(j-1)/2]%p*a[k][j]%p*c(i+j-1, j)%p)%p;
                g[i+j][j] = (g[i+j][j]+(g[i][k]+(n-i)*f[i][k]%p)%p*b[j*(j-1)/2]%p*a[k][j]%p*c(i+j-1, j)%p)%p;
            }
        }
    }

    ll ans=0;
    for (int i=1; i<n; i++) ans = (ans+g[n][i])%p;
    ans = ans*qpower(n-1, p-2)%p;
    printf("%lld\n", ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
